<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../script/bootstrap-3.3.7.min.css">
    <script src="../script/jquery-1.10.min.js"></script>
    <script>

        function display() {
                aaa =1
                var bbb
                bbb =2
        }
        function display1() {
            if (typeof(bbb) == undefined ) {
                alert('aaa:' + aaa + " " + "bbb: " + bbb)
            }
            else{
                alert('aaa:' + aaa )
            }

            }

    </script>
</head>
<body>
<div class="container">
    <div class="row">
    <div class="col-md-12">
        <p style="color: red;font-size: 1.5em;"></p>
    </div>
</div>
    <div class="row">
        <div>
            <textarea id = "text1" rows="15" cols="50"></textarea>
            <script>
                str='function display() {\n' +
                    '     aaa =1 没有写var 默认window.aaa  全局变量\n' +
                    '      var bbb 此函数以外不能使用bbb \n'+
                    '      bbb =2\n' +
                    '   }\n' +
                    '  function display1() {\n' +
                    '      if (typeof(bbb) == undefined ) {\n' +
                    '         alert(\'aaa:\' + aaa + " " + "bbb: " + bbb)\n' +
                    '      }\n' +
                    '       else{\n' +
                    '          alert(\'aaa:\' + aaa )\n' +
                    '        }\n' +
                    '\n' +
                    '  }'
                document.getElementById("text1").value=str
            </script>
        </div>
    </div>
    <div class="row">
    <div class="col-md-6 col-md-offset-2">
        <div><button onclick="display()" class="btn btn-danger">先执行dispaly 生成变量</button></div>
        <div><button onclick="display1()" class="btn btn-danger">在执行display1</button></div>
    </div>
    </div>

    <p class="page-header"></p>


</div>
<script>


</script>
</body>
</html>